<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title>运管系统</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<link rel="stylesheet" type="text/css"
	href="../../lib/bootstrap/css/bootstrap.css">

<link rel="stylesheet" type="text/css"
	href="../../stylesheets/theme.css">
<link rel="stylesheet"
	href="../../lib/font-awesome/css/font-awesome.css">


<script src="../../lib/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/bootstrap/js/bootstrap.js"></script>
<script src="../../lib/jquery.validate.min.js"></script>
<script src="../../lib/jquery.cookie.js"></script>

<script src="../../js/init.js"></script>

<!-- Demo page code -->



<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="lib/html5.js"></script>
    <![endif]-->


</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body class="">
	<!--<![endif]-->
	<div class="navbar"></div><div class="common"></div>

	<div class="sidebar-nav"></div>



	<div class="content">
		<div class="well">
			<ul class="nav nav-tabs">
			    	<li class="active"><a href="#profile" data-toggle="tab">修改密码</a></li>
			</ul>
			<div id="myTabContent" class="tab-content">
			
				<div class="tab-pane active in" id="profile">
				
					<form id="form_changePwd">

						<label>当前密码</label>
						<input id="input_originalPwd" required name="originalPwd" type="password" class="input-xlarge">

						<label>新密码</label>
						<input id = "input_newPwd1" required name="newPwd1"  type="password" class="input-xlarge">
						
						<label>新密码确认</label> 
						<input id ="input_newPwd2"  required name="newPwd2"  type="password" class="input-xlarge">
				
						<div >
						    <button id="button_change" type="button" class="btn btn-primary pull-left">确认修改</button>
					    </div>
						<div id="wr" class="pull-left">
						   <label id="alertinfo" style="display:none;" class="alert-danger ">用户名或密码错误</label>
                  	 </div>
					</form>
				
				</div>
			</div>

		</div>

	</div>


	<script type="text/javascript">
//      $("[rel=tooltip]").tooltip();
//      $(function() {
//      $('.demo-cancel-click').click(function(){return false;});
//        });
        
        $(function() {
        	initAdminNavBar(); initCommon();
        	initSideBar('system-management','change-pwd');
        });
        
        $("#form_changePwd").validate(
                {
                	errorClass:"alert-danger",
                	messages:{
                		originalPwd:{required:"手机号不能为空"},
                		newPwd1:{required:"新密码不能为空"},
                		newPwd2:{required:"确认密码不能为空"}
                	}
                }		
        );
        
        $("#button_change").on("click",function(){
        	//$("#alertinfo").hide();
        	if ($("#form_changePwd").valid()) {
        	   	var originalPwd = $("#input_originalPwd").val();
            	var password1 = $("#input_newPwd1").val();
             	var password2 = $("#input_newPwd2").val();
        		
            	if(password1 != password2){
             		$("#alertinfo").text("两次密码输入不一致");
             		$("#alertinfo").show();
                    return; 		
            	}
            	
            	
            	
            	//POST /api/v1/users/{userId}/Password/change
            	$.ajax({
    				contentType:"application/json",
            		url:api_base_url+"v1/users/" +$.cookie("userId")+"/Password/change?originalPwd="+originalPwd,
            		dataType: "json",
            		type:'post',
            		data:password1,
            		
            		success: function(data){
            			if(data.code == "200"){
            				window.location.href="../account/sign-in.html";
            			}else{
            				
            				 $("#alertinfo").text(data.msg);
            				 $("#alertinfo").show();
            			}
            		},
            		error:function(data){
           			 $("#alertinfo").text('网络错误');
       				 $("#alertinfo").show();
       				
           			}
            	});
		
             	
        		
        		
				
			}
        	
        });
        
        
        
    </script>

</body>
</html>


